home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / science / piw131.zip / MULTIFDW.H < prev    next >
Text File  |  1994-07-29  |  7KB  |  165 lines

  1. // ------- MultiFDW.h  Multiple-precision floating decimal algorithms
  2. /*
  3.   Version : Version 3.11, last revised: 1994-07-29, 0600 hours
  4.   Author  : Copyright (c) 1981-1994 by author: Harry J. Smith,'
  5.   Address : 19628 Via Monte Dr., Saratoga, CA 95070.  All rights reserved.
  6. */
  7.  
  8. #ifndef MultiFD_H
  9. #define MultiFD_H
  10.  
  11. #include "MultiIDW.h" // Multiple-precision integer decimal algorithms module
  12. #include <conio.h>
  13. #include <math.h>
  14. #include <string.h>
  15. #include <stdlib.h>
  16.  
  17. // Developed in Turbo Pascal 5.5.  Converted to Borland C++ 3.1 for Windows.
  18.  
  19. // ------- The following are set when MultiFInit is called
  20. extern Mu1Digit FRound;   // Floating point rounding constant, Base / 2 or 0
  21. extern long     FMC;      // Current max # of super digits in a result
  22. extern long     FTn;      // Current # of super digits to truncate display
  23. extern long     FDn;      // Current max decimal digits to display
  24. extern Bool     ScieN;    // Force scientific notation on flag
  25. extern Bool     Expanded; // True if running in expanded precision
  26. extern long     FMCB;     // Base FMC when running expanded precision
  27.  
  28. // ------- A multiple-precision signed floating
  29. class MultiF : public MultiSI {
  30. public:
  31.   long C; // Characteristic, 2 => * Base ** 2
  32.  
  33.   // ------- CONSTRUCTORS
  34.  
  35.   // ------- constructor for a null MultiF
  36.   MultiF() : MultiSI() { C = 0; }
  37.   // ------- constructor with just a max size
  38.   MultiF( long NMaxI) : MultiSI( NMaxI) { C = 0; } 
  39.  
  40.  
  41.   // ------- DESTRUCTOR
  42.  
  43.   ~MultiF() {;}
  44.  
  45.   // ------- MEMBER FUNCTIONS
  46.  
  47.   virtual void Clear() { MultiSI::Clear(); C = 0; } // Set value = 0
  48.   void SetTo( MultiF& X); // this = X
  49.   void Norm();            // Normalize this
  50.   void RAdd( MultiF& X);  // this = this + X
  51.   void RSub( MultiF& X);  // this = this - X
  52.   void Add( MultiF& X, MultiF& Y); // this = X + Y
  53.   void Sub( MultiF& X, MultiF& Y); // this = X - Y
  54.   void Value( char *St, int& i);
  55.     // Convert String to 'this', return i # of character used
  56.   void SetTo1( Mu1Digit D1); // this = D1 Mod Base
  57.   void SetToD( double Db);   // this = Db Mod Base**4
  58.   void Get1( Mu1Digit& D1);  // D1 = this Mod Base
  59.   void GetD( double& Db);    // Db = this Mod Base**4
  60.   void GetDIn( double& Db, double Lo, double Hi); // Db = this Mod Base**4,
  61.                                                   //   in a range, + or -
  62.   void ShiftR( long R); // this = this, R "digits" lost, unnormalized
  63.   void ShiftL( long L); // this = this, R "digits" more, unnormalized
  64.   void RAdd1( Mu1Digit D1);  // this = this + D1
  65.   void Add1( MultiF& X, Mu1Digit D1); // this = X + D1
  66.   TriS Comp( MultiF& X);// Comp = signum( this - X), signum function = -1,0,+1
  67.   void Writ( ostream& Out, long& Tot); // Output this as a line of text
  68.   void WritLn( ostream& Out, long& Tot); // Output this and a new line
  69. //void ShortWr( ostream& Out, long Short);
  70.     // Output this in short form ... if more than Short digits
  71. //void ShortWrLn( ostream& Out, long Short);
  72.     // Output this short and a new line
  73.   void RMul1( Mu1Digit D1); // this = this * D1
  74.   void Mul1( MultiF& X, Mu1Digit D1); // this = X * D1
  75. //void MulL( MultiF& X, MultiF& Y);  // this = X * Y, Low-level
  76.   void MulSlow( MultiF& X, MultiF& Y); // this = X * Y (Slow)
  77.   void MulFast( MultiF& X, MultiF& Y);  // this = X * Y (Fast)
  78.   void Mul( MultiF& X, MultiF& Y);   // this = X * Y (Fast or Slow)
  79.   void RMul( MultiF& X); // this = this * X
  80.   void Sq( MultiF& X);   // this = X * X
  81.   void RSq(); // this = this * this
  82.   void Pow( MultiF& B, MultiF& P); // this = (B ** P) Mod MuMB
  83.   void RPow( MultiF& P); // this = (this ** P) Mod MuMB
  84.   void RDiv1( Mu1Digit D1); // this = this / D1
  85.   void Div1( MultiF& U, Mu1Digit D1);      // this = U / D1
  86.   void Divi( MultiF& U, MultiF& D);    // this = U / D
  87. //void DivSlow( MultiF& U, MultiF& D); // this = U / D
  88. //void DivFast( MultiF& U, MultiF& D); // this = U / D
  89.   void RDiv( MultiF& D);                // this = this / D
  90.   void Fac( MultiF& X);  // this = (X !) Mod MuMB = 1*2*3*...*X
  91.   void RFac();            // this = (this !) Mod MuMB = 1*2*3*...*X
  92. //void SqRtRemSlow( MultiF& X, MultiF& R); // this = SqRt(X), R = Rem
  93. //void SqRtRemFast( MultiF& X, MultiF& R); // this = SqRt(X), R = Rem
  94.   void SqRoot( MultiF& X);                  // this = SqRt(X)
  95.   void RSqRt();                              // this = SqRt( this)
  96. //void ReadF( FILE* R, char* Name, int& OK); // Read MultiF from a file
  97.   void Inte( MultiF& X); // this = Integer part of X
  98.   void RInt(); // this = Integer part of this
  99.   void Fract( MultiF& X); // this = Fractional part of X
  100.   void RFrac(); // this = Fractional part of this
  101.   void Lop( MultiF& X); // this = X with one less super digit
  102.   void RLop(); // this = this with one less least significant "digit"
  103. //MultiF operator+ (MultiF& X);  // overloaded + infix add operator
  104. //inline MultiF& operator<<= (MultiF& X);//overloaded <<= assignment operator
  105. };
  106.  
  107. // ------- Multi's inline methods
  108.  
  109. // --end-- MultiF's inline methods
  110.  
  111. // ------- The following is initialized in module MultiFW.Cpp
  112. // extern MultiF ????; // ????
  113.  
  114. // ------- Other services
  115.  
  116. // ------- Returns max of X, Y
  117. int Max(int X, int Y);
  118.  
  119. // ------- Returns min of X, Y
  120. int Min(int X, int Y);
  121.  
  122. // ------- Returns max of X, Y
  123. long MaxL(long X, long Y);
  124.  
  125. // ------- Returns min of X, Y
  126. long MinL(long X, long Y);
  127.  
  128. // ------- Returns max of X, Y
  129. double MaxD(double X, double Y);
  130.  
  131. // ------- Returns min of X, Y
  132. double MinD(double X, double Y);
  133.  
  134. // ------- Compute X = Pi by algorithm a
  135. void PiAA( MultiF& X, Bool WReset, Bool ReStart);
  136. // Uses 4 large "Registers" X, Y, Z, and T.  L is small.
  137. // if WReset then Write reset data after each iteration
  138. // if ReStart then Read reset data before starting
  139.  
  140. // ------- Compute X = Pi by algorithm b
  141. void PiAB( MultiF& X, Bool WReset, Bool ReStart);
  142. // Uses 4 large "Registers" X, Y, Z, and T.  L is small.
  143. // if WReset then Write reset data after each iteration
  144. // if ReStart then Read reset data before starting
  145.  
  146. // ------- Compute X = Pi by algorithm b, set Pi to its computed value
  147. void PiTo( MultiF& X);
  148.  
  149. // ------- Output String and line feed every 80,
  150. //         Tot = characters on line so far
  151. void Write80( ostream& Out, char *St, long& Tot);
  152.  
  153. // ------- Output String and line feed every 80,
  154. //         Tot = characters on line so far, followed by line feed
  155. void Write80Ln( ostream& Out, char *St, long& Tot);
  156.  
  157. // ------- Initialize Multi-precision floating decimal package
  158. void InitMultiF();
  159.  
  160. // --end-- Other services
  161.  
  162. #endif  // ifndef MultiF_H
  163.  
  164. // --end-- MultiFDW.h  Multiple-precision floating decimal algorithms
  165.